import { _decorator, Component, Node, director} from 'cc';
import { NakamaManager } from './NakamaManager';
const { ccclass, property } = _decorator;


@ccclass('LaunchManager')
export class LaunchManager extends Component {

    private nakama = NakamaManager.getInstance();

    start() {
        this.checkToken(true);
    }

    async checkToken(alwaysSignin: boolean) {
        if (alwaysSignin) {
            director.loadScene("signin");
            return;
        }
        try {
           const success = await this.nakama.autoSignIn()
           if (success) {
                director.loadScene("lobby");
           } else {
                director.loadScene("signin");
           }
        } catch(err) {
            console.error("自动登录异常:", err.message);
            director.loadScene("signin");
        }
    }
    

    update(deltaTime: number) {
        
    }
}

